package com.nhjf.mobile.controller.userFollow;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nhjf.common.page.Pagination;
import com.nhjf.model.system.AdminSession;
import com.nhjf.model.system.User;
import com.nhjf.model.teachers.ReviewPainting;
import com.nhjf.model.teachers.UserFollow;
import com.nhjf.pojo.qo.system.AdminSessionQo;
import com.nhjf.pojo.qo.system.UserQo;
import com.nhjf.pojo.qo.teachers.UserFollowQo;
import com.nhjf.service.system.AdminSessionService;
import com.nhjf.service.system.UserService;
import com.nhjf.service.teachers.UserFollowService;

import net.sf.json.JSONObject;

@RequestMapping("/userFollow")
@Controller
public class userFollowController {

	@Autowired
	private UserFollowService followService;
	@Autowired
	private UserService userService;
	@Autowired
	private AdminSessionService adminSessionService;


	/**
	 * 查询全部粉丝 和关注人 （暂时没用）
	 * @param token
	 * @param followUserId
	 * @param fansUserId
	 * @return
	 */
	@RequestMapping("/userFollow_query")
	@ResponseBody
	public String queryUserfollow(@RequestParam(value="token", required=true)String  token,String followUserId,String fansUserId,@RequestParam(value = "page", defaultValue = "1")Integer page) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					UserFollowQo followQo=new UserFollowQo();
					followQo.setSeachFansUser(true);
					followQo.setSeachFollowUser(true);
					Pagination pagination = new Pagination();
					pagination.setPageSize(10);
					pagination.setPageNo(page);
					pagination.setCondition(followQo);
					pagination = followService.queryPagination(pagination);
					List<UserFollow> uList= (List<UserFollow>)pagination.getList();
					for (UserFollow userFollow : uList) {
						if(userFollow.getFansUser()!=null && userFollow.getFollowUser()!=null) {
							userFollow.getFansUser().setUserPassword("");
							userFollow.getFollowUser().setUserPassword("");
						}
						
					}
					resMap.put("code", "200");
					resMap.put("message", uList);
					return JSONObject.fromObject(resMap).toString();
				}
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		resMap.put("code", "500");
		resMap.put("message", "系统异常！");
		return JSONObject.fromObject(resMap).toString();
	}

}
